package com.note.servlet.user;

import com.note.pojo.Users;
import com.note.service.user.userService;
import com.note.service.user.userServiceImpl;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class updatePasswd extends HttpServlet {
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Users user = (Users) req.getSession().getAttribute("userSession");
        int id = (int) user.getId();
        String newpassword = req.getParameter("newpasswd");
        userService u = new userServiceImpl();
        boolean b = u.updatePassword(newpassword, id);
        if (b){
            resp.sendRedirect(req.getContextPath()+"/logout");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
